//
//  MYBaseViewController.swift
//  MYSinaWeico
//
//  Created by Magic Yu on 16/4/8.
//  Copyright © 2016年 Magic Yu. All rights reserved.
//

import UIKit

class MYBaseViewController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate = self
        
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        print(childViewControllers.count)
        if childViewControllers.count > 0 {
            var backTitle = "返回"
            if childViewControllers.count == 1 {
            backTitle = childViewControllers.first?.title ?? ""
            }
        
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: "navigationbar_back_withtext", title: backTitle, target: self, action: "back")
            //解决页面卡顿问题
            viewController.view.backgroundColor = UIColor.whiteColor()
            //隐藏底部工具栏
            viewController.hidesBottomBarWhenPushed = true
        }
        
        //必须调用父类的方法 否则一些设置不显示
        //不能写在前面 必须在设置完之后再调用父类的方法
        super.pushViewController(viewController, animated: true)
        
    }
    
    @objc private func back() {
    
        popViewControllerAnimated(true)
    }
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        return childViewControllers.count != 1
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}




